package com.crazypos.controller.admin;

import com.crazypos.common.ApiRestResponse;
import com.crazypos.common.utils.SecurityUtil;
import com.crazypos.pojo.bo.CreateProductBO;
import com.crazypos.security.entity.UserDetailEntity;
import com.crazypos.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/admin/product")
public class AdminProductController {

    @Autowired
    private IProductService productService;

    @PreAuthorize("hasRole('ADMIN')")
    @GetMapping("/list")
    public ApiRestResponse getProductList() {
        return ApiRestResponse.success();
    }

    @PreAuthorize("hasRole('ADMIN')")
    @PostMapping("/create")
    public ApiRestResponse createProduct(CreateProductBO bo) throws IOException {
        UserDetailEntity userInfo = SecurityUtil.getUserInfo();
        productService.createProduct(bo, 1, userInfo.getId(), userInfo.getOrganizationId());
        return ApiRestResponse.success();
    }

    @PreAuthorize("hasRole('ADMIN')")
    @PostMapping("/update")
    public ApiRestResponse updateProduct() {
        return ApiRestResponse.success();
    }

    @PreAuthorize("hasRole('ADMIN')")
    @PostMapping("/delete")
    public ApiRestResponse deleteProduct() {
        return ApiRestResponse.success();
    }
}
